<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/admin/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/admin/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="/admin/lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>生产厂家管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 基础信息 <span
        class="c-gray en">&gt;</span> 生产厂家信息 <a class="btn btn-primary radius r"
                                                style="line-height:1.6em;margin-top:3px"
                                                href="javascript:location.replace(location.href);" title="刷新"><i
            class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
			<a class="btn btn-primary radius" onclick="edit1(0,'')"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
		</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-responsive" id="datatable">
            <thead>
            <tr class="text-c">
                <th hidden>ID</th>
                <th>名称</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $item)
                <tr class="text-c">
                    <td id="id-{{$item->id}}" hidden>{{$item->id}}</td>
                    <td class="name">{{$item->name}}</td>
                    <td>
                        <a onclick="edit1({{$item->id}},'{{$item->name}}')"
                           class="btn btn-primary size-MINI radius">修改</a>
                        <a onclick="del({{$item->id}},this)" class="btn btn-danger size-MINI radius">删除</a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/admin/lib/layer/3.1.1/layer.js"></script>
<script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript"
        src="/admin/static/myfolder/js/common.js?ver={{config('constant.static_res_ver')}}"></script>

<script type="text/javascript">
    var index;
    /*删除*/
    function del(id, obj) {
        layer.confirm('确认要删除吗？', function (index) {
            let oData = {}, param = {id: id, _token: '{{csrf_token()}}',_form_token :'{{csrf_form_token()}}'}, url = 'del', type = 'post';
            oData.param = param;
            ajax(type, url, oData, callback);

            function callback(data) {
                if (data == 1) {
                    $(obj).parents('tr').remove();
                    layer.msg('删除成功!', {icon: 1, time: 2000});
                    setTimeout(function (){
                        window.location.reload()
                    },2000)
                } else {
                    layer.msg('删除失败!', {icon: 2, time: 2000});
                }
            }
        });
    }

    //添加，修改提交
    function edit(id) {
        let name = $('input[name=name]').val();
        let oData = {}, param = {id: id, name: name, _token: '{{csrf_token()}}',_form_token :'{{csrf_form_token()}}'}, url = 'edit', type = 'post';
        oData.param = param;
        ajax(type, url, oData, callback);

        function callback(data) {
            let res = parseInt(data);
            if (res > 0) {
                layer.msg('操作成功！', {icon: 1, time: 1000});
                setTimeout(function (){
                    window.location.reload()
                },2000)
            } else {
                layer.msg('操作失败！', {icon: 5, time: 2000});
            }
            if (id === 0) {
                if (data !== '0') {
                    let str = '<tr class="text-c">\n' +
                        '                <td id="id-' + data + '" hidden>' + data + '</td>\n' +
                        '                <td class="name">' + name + '</td>\n' +
                        '                <td>\n' +
                        '                    <a onclick="edit1(' + data + ',\'' + name + '\')" class="btn btn-primary size-MINI radius">修改</a>\n' +
                        '                    <a onclick="del(' + data + ',this)" class="btn btn-danger size-MINI radius">删除</a>\n' +
                        '                </td>\n' +
                        '            </tr>'
                    $('#datatable > tbody').prepend(str);
                }
            }else{
                $("#id-"+id).siblings('td.name').text(name);
                layer.close(index);
            }
        }
    }

    //添加，修改页面
    function edit1(id, name) {
        let content = '<form class="form form-horizontal" id="form" autocomplete="off" >\n' +
            '            <div class="row cl">\n' +
            '                <label class="form-label col-sm-3"><span class="c-red">*</span>名称：</label>\n' +
            '                <div class="formControls col-sm-6">\n' +
            '                    <input type="text" class="input-text" value="' + name + '" placeholder="" id="name" name="name" autofocus="autofocus">\n' +
            '                </div>\n' +
            '            </div>\n' +
            '            <div class="row cl">\n' +
            '                <div class="text-c">\n' +
            '                    <input class="btn btn-primary radius" onclick="edit(' + id + ')" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">\n' +
            '                </div>\n' +
            '            </div>\n' +
            '        </form>';
        index = layer.open({
            type: 1,
            shade: 0.8,
            title: '添加',
            area: ['50%', '50%'],
            shadeClose: true,//点击外围关闭弹窗
            content: content, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
        });
    }
</script>
</body>
</html>
